$(document).ready(function () {
    setTimeout(function () {
        var $sliderItems = $(".slider-items li");
        console.log($sliderItems);
        var html = "";
        for(var i=0;i<$sliderItems.length;i++){
            html += `
             <li ></li>
            `;
        }
        $(".point").html(html);
        var $points = $(".point li");
        $sliderItems.eq(0).css("display","block");
        $points.eq(0).addClass("active");
        var len = $sliderItems.length;
        var index = 1;
        var previous = 0;
        var j = 0;
        function change() {
            if(index >= len){
                index = 0;
            }
            if(index < 0) {
                index = len-1;
            }
            j = index;
            console.log(index);
            $sliderItems.eq(previous).fadeOut(1000);
            $sliderItems.eq(index).fadeIn(1000);
            $points.removeClass("active");
            $points.eq(index).addClass("active");

        }
        function start() {
            previous = index-1;
            change();
            index++;
        }
        var timer = setInterval(start,4000);
        $(".point li").hover(function () {
            clearInterval(timer);
            previous = j;
            index = $(this).index();
            change();
        },function () {
            timer = setInterval(start,4000);
        })
        $sliderItems.hover(function () {
            clearInterval(timer);
        },function () {
            timer = setInterval(start,4000);
        })
        $("#slider-box").hover(function () {
            $(".previous").fadeIn(500);
            $(".next").fadeIn(500);
        },function () {
            $(".previous").fadeOut(500);
            $(".next").fadeOut(500);
        })
        $(".previous").click(function () {
            clearInterval(timer);
            previous=j;
            j--;
            index=j;
            change();
            timer=setInterval(start,4000);
        });
        $(".next").click(function () {
            clearInterval(timer);
            previous=j;
            j++;
            index=j;
            change();
            timer=setInterval(start,4000);
        });
    },200)
    // 初始化

})